home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / amigaoscd / amigapluscd / AP-Website / forum / wbboard / bbcode.js < prev    next >
Text File  |  2001-06-04  |  6KB  |  213 lines

  1. tags = new Array();
  2.  
  3. function getarraysize(thearray) {
  4.     for (i = 0; i < thearray.length; i++) {
  5.         if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
  6.             return i;
  7.         }
  8.     return thearray.length;
  9. }
  10.  
  11. function arraypush(thearray,value) {
  12.     thearraysize = getarraysize(thearray);
  13.     thearray[thearraysize] = value;
  14. }
  15.  
  16. function arraypop(thearray) {
  17.     thearraysize = getarraysize(thearray);
  18.     retval = thearray[thearraysize - 1];
  19.     delete thearray[thearraysize - 1];
  20.     return retval;
  21. }
  22.  
  23. // *******************************************************
  24.  
  25. function setmode(modevalue) {
  26.     document.cookie = "bbcodemode="+modevalue+"; path=/; expires=Wed, 1 Jan 2020 00:00:00 GMT;";
  27. }
  28.  
  29. function normalmode(theform) {
  30.     if (theform.mode[0].checked) return true;
  31.     else return false;
  32. }
  33.  
  34. function stat(thevalue) {
  35.     document.bbform.status.value = eval(thevalue+"_text");
  36. }
  37.  
  38. // *******************************************************
  39.  
  40. function closetag(theform) {
  41.     if (normalmode(theform))
  42.         stat('enhanced_only');
  43.     else
  44.         if (tags[0]) {
  45.             theform.message.value += "[/"+ arraypop(tags) +"]";
  46.             }
  47.         else {
  48.             stat('no_tags');
  49.             }
  50.     theform.message.focus();
  51. }
  52.  
  53. function closeall(theform) {
  54.     if (normalmode(theform))
  55.         stat('enhanced_only');
  56.     else {
  57.         if (tags[0]) {
  58.             while (tags[0]) {
  59.                 theform.message.value += "[/"+ arraypop(tags) +"]";
  60.                 }
  61.             theform.message.value += " ";
  62.             }
  63.         else {
  64.             stat('no_tags');
  65.             }
  66.         }
  67.     theform.message.focus();
  68. }
  69.  
  70. // *******************************************************
  71. var text = "";
  72. AddTxt = "";
  73. function getActiveText(selectedtext) { 
  74.     text = (document.all) ? document.selection.createRange().text : document.getSelection();
  75.     if (selectedtext.createTextRange) {
  76.         selectedtext.caretPos = document.selection.createRange().duplicate();
  77.     }
  78.     return true;
  79. }
  80.  
  81. function AddText(NewCode,theform) {
  82.     if (theform.message.createTextRange && theform.message.caretPos) {
  83.         var caretPos = theform.message.caretPos;
  84.         caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
  85.     } else {
  86.         theform.message.value+=NewCode
  87.     }
  88.     setfocus(theform);
  89.     AddTxt = "";
  90. }
  91.  
  92.  
  93. function setfocus(theform) {
  94. theform.message.focus();
  95. }
  96.  
  97. function bbcode(theform,bbcode,prompttext) {
  98.     if ((normalmode(theform)) || (bbcode=="IMG")) {
  99.         if (text) { var dtext=text; } else { var dtext=prompttext; }
  100.         inserttext = prompt(tag_prompt+"\n["+bbcode+"]xxx[/"+bbcode+"]",dtext);
  101.         if ((inserttext != null) && (inserttext != ""))
  102.             AddTxt = "["+bbcode+"]"+inserttext+"[/"+bbcode+"] ";
  103.             AddText(AddTxt,theform);
  104.             
  105.         }
  106.     else {
  107.         donotinsert = false;
  108.         for (i = 0; i < tags.length; i++) {
  109.             if (tags[i] == bbcode)
  110.                 donotinsert = true;
  111.             }
  112.         if (donotinsert)
  113.             stat("already_open");
  114.         else {
  115.             theform.message.value += "["+bbcode+"]";
  116.             arraypush(tags,bbcode);
  117.             }
  118.         }
  119.     theform.message.focus();
  120. }
  121.  
  122. // *******************************************************
  123.  
  124. function fontformat(theform,thevalue,thetype) {
  125.     if (normalmode(theform)) {
  126.         if (thevalue != 0) {
  127.             if (text) { var dtext=text; } else { var dtext=""; }
  128.             inserttext = prompt(font_formatter_prompt+" "+thetype,dtext);
  129.             if ((inserttext != null) && (inserttext != ""))
  130.                 AddTxt = "["+thetype+"="+thevalue+"]"+inserttext+"[/"+thetype+"] ";
  131.                 AddText(AddTxt,theform);
  132.                 
  133.             }
  134.         }
  135.     else {
  136.         theform.message.value += "["+thetype+"="+thevalue+"]";
  137.         arraypush(tags,thetype);
  138.         }
  139.     theform.sizeselect.selectedIndex = 0;
  140.     theform.fontselect.selectedIndex = 0;
  141.     theform.colorselect.selectedIndex = 0;
  142.     theform.message.focus();
  143. }
  144.  
  145. // *******************************************************
  146.  
  147. function namedlink(theform,thetype) {
  148.     if (text) { var dtext=text; } else { var dtext=""; }
  149.     linktext = prompt(link_text_prompt,dtext);
  150.         var prompttext;
  151.         if (thetype == "URL") {
  152.             prompt_text = link_url_prompt;
  153.             prompt_contents = "http://";
  154.             }
  155.         else {
  156.             prompt_text = link_email_prompt;
  157.             prompt_contents = "";
  158.             }
  159.     linkurl = prompt(prompt_text,prompt_contents);
  160.     if ((linkurl != null) && (linkurl != "")) {
  161.         if ((linktext != null) && (linktext != "")) {
  162.             AddTxt = "["+thetype+"="+linkurl+"]"+linktext+"[/"+thetype+"] ";
  163.             AddText(AddTxt,theform);
  164.             
  165.             }
  166.         else{
  167.             AddTxt = "["+thetype+"]"+linkurl+"[/"+thetype+"] ";
  168.             AddText(AddTxt,theform);
  169.             
  170.         }
  171.     }
  172. }
  173.  
  174. // *******************************************************
  175.  
  176. function dolist(theform) {
  177.     listtype = prompt(list_type_prompt, "");
  178.     if ((listtype == "a") || (listtype == "1")) {
  179.         thelist = "[list="+listtype+"]\n";
  180.         listend = "[/list="+listtype+"] ";
  181.         }
  182.     else {
  183.         thelist = "[list]\n";
  184.         listend = "[/list] ";
  185.         }
  186.     listentry = "initial";
  187.     while ((listentry != "") && (listentry != null)) {
  188.         listentry = prompt(list_item_prompt, "");
  189.         if ((listentry != "") && (listentry != null))
  190.             thelist = thelist+"[*]"+listentry+"\n";
  191.         }
  192.     AddTxt = thelist+listend;
  193.     AddText(AddTxt,theform);
  194.  
  195. }
  196.  
  197. // *******************************************************
  198.  
  199. function smilie(thesmilie) {
  200.     AddSmile = " "+thesmilie+" ";
  201.     theform = bbform;
  202.     AddText(AddSmile,theform);
  203. }
  204.  
  205. function opensmiliewindow(x,y,sid,boardid,styleid) {
  206.         window.open("moresmilies.php?sid="+sid+"&boardid="+boardid+"&styleid="+styleid, "smilies", "toolbar=no,scrollbars=yes,resizable=yes,width="+x+",height="+y);
  207. }
  208.  
  209. // *******************************************************
  210.  
  211. function gethelp() {
  212.     alert(HELPTEXT);
  213. }